package util;

import entity.Blog;

/**
 * 分页的工具类
 */

import java.util.List;

public class Page {

    //总页数
    private int totalPageCount = 0;
    //页面大小，即每页显示记录数
    private int pageSize = 5;
    //总记录数
    private int totalCount;
    //当前页码
    private int currPageNo = 1;


    //获取总页数的方法
    public int getTotalPageCount() {
        if (totalCount % pageSize==0){
            this.totalPageCount=totalCount/pageSize;
        }else {
            this.totalPageCount=totalCount/pageSize+1;
        }
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {

        this.currPageNo = currPageNo;
    }


    //获取当前页查询的片段数据中，第一条记录的下标
    public int getFirstRecordIndex(){
        return (currPageNo-1)*pageSize;
    }

    //获取下一页的页码
    public int getNextPageNo(){
        if (currPageNo==this.getTotalPageCount()){
            return currPageNo;
        }else {
            return currPageNo+1;
        }
    }

    //获取上一页的页码
    public int getPrevPageNo(){
        if (currPageNo==1){
            return currPageNo;
        }else {
            return currPageNo-1;
        }
    }

}
